package com.ys.controller;

import com.ys.config.WebSocketServer;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @ClassName WebsocketController
 * @Author 1628994918qq.com
 * @Date 2023/2/27 9:33
 */
@CrossOrigin("*")
@RestController
@RequestMapping("/socket")
public class WebsocketController {

    @Resource
    private WebSocketServer webSocketServer;

    /**
     * 发送消息
     */
    @GetMapping(path = "publish")
    public String publish(String message, String userId) {
        //创建业务消息信息
        webSocketServer.sendOneMessage(userId, message);
        return "success";
    }

}
